package com.example.demo.controller;
import com.example.demo.entity.Account;
import com.example.demo.result.RestBean;
import com.example.demo.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController

public class AccountController {

    @Autowired
    AccountService accountService;

    @RequestMapping("/login")
    public RestBean login(@RequestBody Account account) {

        String username = account.getUsername();
        String password = account.getPassword();
        Account account1 = accountService.login(username,password);

        if (account1 == null) {
            System.out.println("登录失败！");
            return RestBean.failure(404,account1);
        }
        else {
            System.out.println("登录成功！");
            return RestBean.success(account1);
        }
    }
}
